package  
{
	import flash.net.*;
	import mx.rpc.soap.*;
	import mx.core.*;
	import mx.rpc.events.*;
	
	/**
	 * ...
	 * @author Diego Furque
	 */
	public class WSConnection 
	{
		private var _ws	:WebService;
		private var _transaction :Operation;
		private var _wsdl :String;
		private var _action :String;
		private var _args :Object;
		private var _resultFormat :String;
		private var _result :String;
		
		public function WSConnection() 
		{
			
		}
		
		public function get wsdl () :String
		{
			return this._wsdl;
		}

		public function get action () :String
		{
			return this._action;
		}

		public function get args () :Object
		{
			return this._args;
		}
		
		public function get resultFormat () :String
		{
			return this._resultFormat;
		}		
		
		public function get result () :String
		{
			return this._result;
		}	
		
		public function set wsdl ( wsdlParam :String ) :void
		{
			this._wsdl = wsdlParam;
		}

		public function set action ( actionParam :String) :void
		{
			this._action = actionParam;
		}

		public function set args ( argsParam :Object ) :void
		{
			this._args = argsParam;
		}

		public function set resultFormat ( resultFormatParam :String ) :void
		{
			this._resultFormat = resultFormatParam;
		}
		
		public function set result ( resultParam :String ) :void
		{
			this._resultFormat = resultParam;
		}
		
		public function conn() :void
		{
			this._ws = new WebService()
			this._ws.addEventListener( "load", loaded );
			this._ws.loadWSDL( this._wsdl );
		}	
		
		private function loaded( evt :LoadEvent ) :void
		{
			( this._ws.getOperation( this._action ) as Operation ).resultFormat = this._resultFormat;
			this._ws.getOperation( this._action ).arguments = this._args;
			this._transaction = ( ( this._ws.getOperation( this._action ) ) as Operation );
			this._transaction.addEventListener( "fault", wsdlFault );
			this._transaction.addEventListener( "result", wsdlResult );
			this._transaction.send();
		}	

		private function wsdlFault( evt :FaultEvent) :void
		{
			this._result = String ( evt.fault );
			//trace( evt.fault );
		}

		private function wsdlResult( evt :ResultEvent ):void
		{
			this._result = String ( evt.result );
			//trace( evt.result );
			var myResult :Object = evt.result;
			var len :Number = myResult.length;
			var xml :XML = XML(evt.result);
		}
	}
}